//
// Created by xili on 2024/8/13 20:28.
// GO BIG OR GO HOME.
//

#include "leetcode.h"

class Solution {
public:
    int countStudents(vector<int> &students, vector<int> &sandwiches) {
        int s1 = accumulate(students.begin(), students.end(), 0);
        int s0 = students.size() - s1;
        for (auto &item: sandwiches) {
            if (item && s1 > 0) {
                s1--;
            } else if (!item && s0 > 0) {
                s0--;
            } else {
                break;
            }
        }
        return s1 + s0;
    }
};